/**
 * $Id: bencode.c 1 2009-05-04 19:40:28Z hannes@napoleon.bin-laden.biz $
 * Bencode functions.
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "bencode.h"

/**
 * benc_str() encodes a string in bencode.
 *
 * Example:
 * 3:foo represents the string "foo".
 */
char *benc_str(char *msg)
{
    char *buf = malloc(128);
    memset(buf, 0, 128);
    sprintf(buf, "%i:%s", strlen(msg), msg);
    return buf;
}


/**
 * benc_int() encodes an integer in bencode.
 *
 * Example:
 * i7e represents the integer 7.
 */
char benc_int(int val)
{
	char benc_str[256];
	sprintf(benc_str, "i%ie", val);
	return val;
}

